package fr.nantes.univ.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fr.nantes.univ.DAO.AddressDAO;
import fr.nantes.univ.DAO.UserDAO;
import fr.nantes.univ.EntityBeans.Address;
import fr.nantes.univ.EntityBeans.User;

@SuppressWarnings("serial")
public class AddressesServlet extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		
		HttpSession session = request.getSession(true);
		
		List<Address> addresses = AddressDAO.findByUser(String.valueOf(session.getAttribute("id")));
		request.setAttribute("addresses", addresses);
		
		User user = UserDAO.findById(String.valueOf(session.getAttribute("id")));
		
		/*response.setContentType("text/html");
		response.getWriter().println(String.valueOf(session.getAttribute("id")));
		response.getWriter().println(user.getEmail());
		for (int i = 0; i<addresses.size(); i++) {
			response.getWriter().println(addresses.get(i).getAddress());
		}
		
		response.getWriter().println("<p><a href=\"/login\">Se connecter</a></p>");*/
		
		RequestDispatcher rd = request.getRequestDispatcher("/myaddresses.jsp");
		rd.forward(request, response);
	}

}
